package PowerWord.Core.Data;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class WebDict {
	private String postUri1 = "http://www.google.com.hk/dictionary?langpair=en%7Czh-CN&q=";
	private String postUri2 = "&hl=zh-CN&aq=f";
	
	public String Search(String word) {
		String rev = "";
		try {
			URL url = new URL(postUri1 + "test" + postUri2);
			HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
			urlConnection.setRequestMethod("GET");
	        urlConnection.setDoOutput(true);
	        urlConnection.setDoInput(true);
	        urlConnection.setUseCaches(false);
	        
			InputStream inStream = urlConnection.getInputStream();
			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inStream));
			String line = bufferedReader.readLine();
            while (line != null) {
            	rev += line;
                line = bufferedReader.readLine();
            }
            bufferedReader.close();
			return rev;
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return word;
	}
}
